﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Dtos;
using RedDragon.ERP.API.Application.Commands.MaterialPlanning;
using RedDragon.ERP.API.Application.Commands.Supplieries;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    /// <summary>
    /// 物料需求计划控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PlansController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PlansController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 物料需求计划添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> CreatePlan(CreatePlanCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 物料需求计划查询列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<PlanDto>>> SearchPlan([FromQuery] SearchPlanCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 物料需求计划删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Result> DeletePlan(DeletePlanCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据物料需求计划ID进行查询
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchPlanId([FromQuery] SearchPlanIdCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 物料需求计划修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdatePlan(UpdatePlanCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 导入物料需求计划信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> ImportPlan(ImportPlanCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
